--
-- Author: shunguo.chen
-- Date: 2019-05-27 20:03:54
--
-- SkillChangeController  技能替换（用在竞速副本中切换技能）
--

local SkillChangeView = import("..views.SkillChangeView")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ControllerBase)

function ClassRef:ctor(data)
    self.super.ctor(self, data)
end

function ClassRef:init()
    self._model = app:getInst("SkillModel")

    self._selectSkillTeam = nil -- SkillPanel 默认选中技能组id
end

function ClassRef:removeListeners()
    self.super.removeListeners(self)

end

function ClassRef:listEvent()
    return { }
end

function ClassRef:openView()
    self._model:C2S_SpeedDungeonRoleSkills()
end

function ClassRef:showView(data)
    if nil == self._view then
        self._view = SkillChangeView.new(app.mvc.VIEWTYPE_BLUR)
        self._view:onCloseView(handler(self, self.closeView))
        self._view:onClearView(handler(self, self.clearView))
        self._view:onOperate(handler(self, self.onOperate))
    end
    self:addChild(self._view, data)

    self._view:show()

    local spectType = self._model:getSpeedSpecType()
    local skills = self._model:getSpeedEquipedSkills()
    self._view:refresh(spectType, skills, self._selectSkillTeam)
    self._selectSkillTeam = nil
end
function ClassRef:clearView()
    if self._view then
        self._view = nil
    end

    self._model:clear()
end

-------------------------------------------------------

-------------------------------------------------------
function ClassRef:onOperate(op, ...)
    -- print("SkillChangeController:onOperate op", op)
    if op == "skill_openMore" then
        self:openMorePanel(...)
    elseif op == "skill_choose" then
        local chooseSkill, sourceSkillIdx = ...
        local params = {}
        params.chooseId = chooseSkill:getId()
        params.index = sourceSkillIdx
        self._selectSkillTeam = chooseSkill:getTeam()
        self._model:C2S_SpeedDungeonChooseSkill(params)
    end
end

function ClassRef:openMorePanel(skill, skillIdx)
    local skills = self._model:getSpeedReplaceSkills()
    self._view:openMorePanel(skills, skill, skillIdx)
end

return ClassRef
